{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Share Your Content Tutorial\n",
    "\n",
    "This is the completed sample for the [Share your content](https://developers.arcgis.com/labs/data/python/share-your-content/) ArcGIS tutorial.\n",
    "\n",
    "[ArcGIS tutorials](https://developers.arcgis.com/labs/) are short guides demonstrating the three phases of building geospatial apps: Data, Design, Develop."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Important Note\n",
    "Please complete the [Import data tutorial](https://developers.arcgis.com/labs/data/python/import-data/) if you have not done so already. You will use the output feature layer from this lab to learn how to find and share an item."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from arcgis.gis import GIS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Log into ArcGIS Online by making a GIS connection using your developer account. Replace `username` and `password` with your own credentials"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter password, please: ········\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "\n",
    "password = getpass.getpass(\"Enter password, please: \")\n",
    "gis = GIS('https://arcgis.com', 'username', password)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Search for the *Trailheads* layer used in the [Import Data](https://developers.arcgis.com/labs/data/python/import-data/) tutorial."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Item title:\"Trailheads\" type:Feature Layer Collection owner:cff_dev>]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_layer_srch_results = gis.content.search(query='title: \"Trailhead*\" AND type: \"Feature Service\"')\n",
    "feature_layer_srch_results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Retrieve the feature layer collection item from the list of results.\n",
    "To check the sharing permissions, click the *thumbnail* link to open the *Item Details* page and find *Shared with* under *Details* on the right."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://cff-dev.maps.arcgis.com/home/item.html?id=05c7df52361747c6a6872a3a6022cd58' target='_blank'>\n",
       "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://cff-dev.maps.arcgis.com/home/item.html?id=05c7df52361747c6a6872a3a6022cd58' target='_blank'><b>Trailheads</b>\n",
       "                        </a>\n",
       "                        <br/><img src='https://cff-dev.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\">Feature Layer Collection by cff_dev\n",
       "                        <br/>Last Modified: March 12, 2019\n",
       "                        <br/>0 comments, 3 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"Trailheads\" type:Feature Layer Collection owner:cff_dev>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_layer_coll_item = feature_layer_srch_results[0]\n",
    "feature_layer_coll_item"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Update the sharing permissions of the layer so that it's available to everyone. You can verify the update by refreshing the thumbnail link!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'results': [{'itemId': '05c7df52361747c6a6872a3a6022cd58',\n",
       "   'success': True,\n",
       "   'notSharedWith': []}]}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_layer_coll_item.share(everyone=True)"
   ]
  }
 ],
 "metadata": {
  "esriNotebookRuntime": {
   "notebookRuntimeName": "ArcGIS Notebook Python 3 Standard",
   "notebookRuntimeVersion": "9.0"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
